package com.rc.evcharger.common.type;

import com.rc.evcharger.common.utils.DataUtil;

import java.lang.reflect.Field;
import java.util.Calendar;

/**
 * Create by Yang on 2019/11/12
 */
public class TimingDate extends BaseType implements DataType {
    String year;     //年
    String month;   //月
    String day;     //日
    String hour;    //小时
    String min;     //分
    String sed;     //秒
    String obligate = "00 00 00 00";

    public TimingDate() {
    }

    public TimingDate(String obligate) {
        this.setDate();
    }

    public String getDate() {
        StringBuffer sb = new StringBuffer();
        sb.append(this.year).append(DataUtil.SPLIT);
        sb.append(this.month).append(DataUtil.SPLIT);
        sb.append(this.day).append(DataUtil.SPLIT);
        sb.append(this.hour).append(DataUtil.SPLIT);
        sb.append(this.min).append(DataUtil.SPLIT);
        sb.append(this.sed).append(DataUtil.SPLIT);
        sb.append("00").append(DataUtil.SPLIT);
        sb.append("00");
        return sb.toString();
    }

    public void setDate() {
        Calendar instance = Calendar.getInstance();
        this.year = (instance.get(Calendar.YEAR) + "").substring(2, 4);
//        this.year = "18";
        this.month = (instance.get(Calendar.MONTH) + 1) + "";
        if (month.length() == 1) {
            this.month = "0" + this.month;
        }

        this.day = instance.get(Calendar.DAY_OF_MONTH) + "";
        if (day.length() == 1) {
            this.day = "0" + this.day;
        }

        this.hour = instance.get(Calendar.HOUR_OF_DAY) + "";
        if (hour.length() == 1) {
            this.hour = "0" + this.hour;
        }

        this.min = instance.get(Calendar.MINUTE) + "";
        if (min.length() == 1) {
            this.min = "0" + this.min;
        }

        this.sed = instance.get(Calendar.SECOND) + "";
        if (sed.length() == 1) {
            this.sed = "0" + this.sed;
        }

//        this.year = "18";
//        this.month = "10";
//        this.day = "10";
//        this.hour = "10";
//        this.min = "10";    //分
//        this.sed = "10";
    }


    @Override
    public String toString() {
        return "TimingData{" +
                "year='" + year + '\'' +
                ", month='" + month + '\'' +
                ", day='" + day + '\'' +
                ", hour='" + hour + '\'' +
                ", min='" + min + '\'' +
                ", sed='" + sed + '\'' +
                '}';
    }

    public String getYear() {
        return year;
    }

    public void setYear(String year) {
        this.year = year;
    }

    public String getMonth() {
        return month;
    }

    public void setMonth(String month) {
        this.month = month;
    }

    public String getDay() {
        return day;
    }

    public void setDay(String day) {
        this.day = day;
    }

    public String getHour() {
        return hour;
    }

    public void setHour(String hour) {
        this.hour = hour;
    }

    public String getMin() {
        return min;
    }

    public void setMin(String min) {
        this.min = min;
    }

    public String getSed() {
        return sed;
    }

    public void setSed(String sed) {
        this.sed = sed;
    }

    public String getObligate() {
        return obligate;
    }

    public void setObligate(String obligate) {
        this.obligate = obligate;
    }

    @Override
    public boolean customField(Field field, StringBuffer sb) {
        return false;
    }

    public static void main(String[] args) {
        TimingDate timingData = new TimingDate();
        timingData.setDate();
        System.out.println(timingData.toString());
    }
}
